package com.wf.day_0607.test4;

import java.io.*;
import java.util.Objects;
import java.util.Properties;

/**
 * @author mpk
 * @since 2024/6/7 18:26:37
 */

/*作业4：有个class.properties文件，文件内容格式如下：
        demo1=com.igeek.javase.ch15.work.Demo1
        demo2=com.igeek.javase.ch15.work.Demo2
        要求写个方法 public static classLoadByKey(String key){} 输入指定的key 以文件中=前面作为key，来加载指定的类（同时执行指定类的静态代码块）*/
public class PropertiesTest {
    public static void main(String[] args) throws IOException {


        try (
            InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(PropertiesTest.class.getResourceAsStream("class.properties")))) {


            Properties properties = new Properties();

            properties.load(reader);

            properties.keySet()
                    .forEach(
                            key ->
                            {
                                try {
                                    Class.forName((String) properties.get(key));
                                } catch (ClassNotFoundException e) {
                                    throw new RuntimeException(e);
                                }
                            }

                    );


        }


    }


}
